const path = require('path')


const { unlink, readdir, stat, rmdir } = require('fs').promises
async function preParellDeep(dir) {
    const statObj = await stat(dir);
    if (statObj.isFile()) {
        await unlink(dir)
    } else {
        let dirs = await readdir(dir)
        dirs = dirs.map(item => preParellDeep(path.join(dir, item)))
        await Promise.all(dirs)
        await rmdir(dir)
    }
}

preParellDeep(path.resolve(__dirname, 'a')).then(res => {
    console.log('删除成功')
})